package cn.com.java.controller;

import cn.com.java.model.SysUserRole;
import cn.com.java.service.SysUserRoleService;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;


@RestController
@RequestMapping("SysUserRole")
@RequiredArgsConstructor
public class SysUserRoleController {

    
    private final SysUserRoleService sysUserRoleService;

    /**
     * 查询所有记录
     *
     * @return 返回集合，没有返回空List
     */
    @RequestMapping("list")
    public List<SysUserRole> listAll() {
        return sysUserRoleService.list();
    }


    /**
     * 根据主键查询
     *
     * @param id 主键
     * @return 返回记录，没有返回null
     */
    @RequestMapping("getById")
    public SysUserRole getById(Long userId) {
        return sysUserRoleService.getById(userId);
    }    
     
    /**
     * 新增，忽略null字段
     *
     * @param sysUserRole 新增的记录
     * @return 返回影响行数
     */
    @RequestMapping("insert")
    public int insert(@RequestBody SysUserRole sysUserRole) {
        return sysUserRoleService.getBaseMapper().insert(sysUserRole);
    }    
      
    /**
     * 修改，忽略null字段
     *
     * @param sysUserRole 修改的记录
     * @return 返回影响行数
     */
    @RequestMapping("update")
    public boolean update(@RequestBody SysUserRole sysUserRole) {
        return sysUserRoleService.updateById(sysUserRole);
    }
    
    /**
     * 删除记录
     *
     * @param sysUserRole 待删除的记录
     * @return 返回影响行数
     */
    @RequestMapping("delete")
    public boolean delete(@RequestBody SysUserRole sysUserRole) {
        return sysUserRoleService.removeById(sysUserRole.getUserId());
    }
    
}